import React, { useState, useEffect } from "react";
const Example2 = () => {
  const [age] = useState(18);
  const [sex] = useState("男");
  const [work] = useState("前端程序员");
  const [count, setCount] = useState(0);
  // 这里的顺序一定要跟下面的字段对应，不然会报错
  // 这里也不能出现判断
  const setCounts = () => {
    setCount(count + 1);
  };
  // hooks生命周期
  // useEffect在首次渲染以及每次渲染都会调用一遍
  useEffect(() => {
    console.log(`你点击了${count}次`);
  });
  return (
    <div>
      <p>Du 今年:{age}岁</p>
      <p>性别:{sex}</p>
      <p>工作是:{work}</p>
      <div>
        <p>You clicked {count} times</p>
        <button onClick={setCounts}>click me</button>
      </div>
    </div>
  );
};
export default Example2;
